<?php
/**
 * Customfields.php
 *
 * PHP version 5
 *
 * LICENSE: This source file is subject to version 2.0 of the Apache license
 * that is available through the world-wide-web at the following URI:
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * @category Controller
 * @package  Controller
 * @author   Alex Kopp <koppa@rpi.edu>
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link     http://http://code.google.com/p/tri-chi/
 */

/**
 * Customfields
 *
 * The model that manages all the Users of the GLOrganizer System
 *
 * The followings are the available columns in table 'customfields':
 *
 * @property string $id
 * @property string $field_type
 * @property string $field_attributes
 * @property string $label
 * @property integer $weight
 *
 * The followings are the available model relations:
 * @property Customfieldvalues[] $customfieldvalues
 *
 * @category Controller
 * @package  Controller
 * @author   Alex Kopp <koppa@rpi.edu>
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link     http://http://code.google.com/p/tri-chi/
 */
class Customfields extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     *
     * @param unknown_type $className unknown
     *
     * @return Customfields the static model class
     */
    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }

    /**
     * Get Table Name
     * 
     * @return string the associated database table name
     */
    public function tableName()
    {
        return 'customfields';
    }

    /**
     * Array Validation Rules
     * 
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
        array('field_type, label, weight', 'required'),
        array('weight', 'numerical', 'integerOnly'=>true),
        array('field_type', 'length', 'max'=>9),
        array('label', 'length', 'max'=>32),
        // The following rule is used by search().
        // Please remove those attributes that should not be searched.
        array('id, field_type, field_attributes, label, weight', 'safe', 'on'=>'search'),
        );
    }

    /**
     * Relations
     * 
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'customfieldvalues' => array(self::HAS_MANY, 'Customfieldvalues', 'custom_field_id'),
        );
    }

    /**
     * Attribute Labels
     * 
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'field_type' => 'Field Type',
            'field_attributes' => 'Field Attributes',
            'label' => 'Label',
            'weight' => 'Weight',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * 
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria=new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('field_type', $this->field_type, true);
        $criteria->compare('field_attributes', $this->field_attributes, true);
        $criteria->compare('label', $this->label, true);
        $criteria->compare('weight', $this->weight);

        return new CActiveDataProvider($this, array('criteria'=>$criteria,));
    }
    
   /**
     * Field Type Options
     * 
     * @return array
     */
    public function getFieldOptions()
    {
        return array('Text Box'=>'Text Box', 'Text Area'=>'Text Area', 'Drop Down' => 'Drop Down');
    }    
}